package com.kungfuhacking.wristbandpro.location.presenter;

import android.util.Log;

import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.CircleOptions;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.kungfuhacking.wristbandpro.location.bean.AreaListEntity;
import com.kungfuhacking.wristbandpro.location.view.ISafeDetailView;


/**
 * Created by Aaron on 17/5/8.
 */

public class ISafeDetailPresenter extends LocationPresenter {

    ISafeDetailView iSafeDetailView;
    private String TAG = getClass().getSimpleName();
    private LatLng mLatLng;

    public ISafeDetailPresenter(ISafeDetailView iSafeDetailView) {
        this.iSafeDetailView = iSafeDetailView;
    }

    public void addLocationMarker(AreaListEntity areaEntity, BitmapDescriptor des) {

        aMap.clear();
        mLatLng = new LatLng(areaEntity.getLatitude(), areaEntity.getLongitude());
        addCircle(mLatLng, areaEntity.getRadius());//添加定位圈
        addMarker(mLatLng, des);
        int scal = 18; //计算地图的缩放比例
        if (areaEntity.getRadius() <= 300) {
            scal = 17;
        } else if (areaEntity.getRadius() > 300 && areaEntity.getRadius() <= 500) {
            scal = 16;
        } else if (areaEntity.getRadius() > 500 && areaEntity.getRadius() <= 800) {
            scal = 15;
        } else if (areaEntity.getRadius() > 800 && areaEntity.getRadius() <= 1000) {
            scal = 14;
        }

        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, scal));//移动到location位置,并设置缩放比例

    }

    private void addCircle(LatLng latlng, double radius) {

        Log.e(TAG, "精度圈的大小:" + radius);

        aMap.addCircle(new CircleOptions().center(latlng).radius(radius).strokeColor(STROKE_COLOR)
                .fillColor(FILL_COLOR).strokeWidth(1f));

    }

    private void addMarker(LatLng latlng, BitmapDescriptor des) {


//        if (this.des == null) {
//            Bitmap bMap = BitmapFactory.decodeResource(this.getResources(),
//                    R.mipmap.ic_thumb);
//            this.des = BitmapDescriptorFactory.fromBitmap(bMap);
//        }

        MarkerOptions options = new MarkerOptions();
        options.icon(des);
        options.anchor(0.5f, 0.5f);
        options.position(latlng);
        aMap.addMarker(options);
    }

}
